<?php

/**
 * 这是一个表 "authitem" 的模型类。
 *
 * 表 'authitem' 有以下字段:
 * @property string $name
 * @property integer $type
 * @property string $description
 * @property string $bizrule
 * @property string $data
 * @property integer $modelid
 * @property string $opertype
 *
 * 以下是表的关联关系:
 * @property Authassignment[] $authassignments
 * @property Authmodule $model
 * @property Authitemchild[] $authitemchildren
 * @property Authitemchild[] $authitemchildren1
 */
class Authitem_new extends CActiveRecord
{
	/**
	 * @return string 表名
	 */
	public function tableName()
	{
		return 'authitem';
	}
        
        public $checks1;
        public $checks2;

	/**
	 * @return array 表字段验证规则的数组。
	 */
	public function rules()
	{
		return array(
			array('name, type', 'required'),
//                        array('name', 'length', 'min'=>3, 'max'=>12),
                        array('name', 'unique', 'message'=>'该记录存在'),
			array('type, modelid', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>64),
			array('opertype', 'length', 'max'=>255),
			array('description, bizrule, data', 'safe'),
			// 以下规则用于验证查询函数，如果不做查询可注释此行。
			array('name, type, description, bizrule, data, modelid, opertype', 'safe', 'on'=>'search'),
		);
	}
        

	/**
	 * @return array 关联关系。
	 */
	public function relations()
	{
		return array(
			'authassignments' => array(self::HAS_MANY, 'Authassignment', 'itemname'),
			'model' => array(self::BELONGS_TO, 'Authmodule', 'modelid'),
			'authitemchildren' => array(self::HAS_MANY, 'Authitemchild', 'parent'),
			'authitemchildren1' => array(self::HAS_MANY, 'Authitemchild', 'child'),
		);
	}

	/**
	 * @return array 自定义字段显示文本标签 (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'name' => '权限名称',
			'type' => 'Type',
			'description' => 'Description',
			'bizrule' => 'Bizrule',
			'data' => 'Data',
			'modelid' => '模块id',
			'opertype' => '操作类型',
		);
	}

	/**
	 * 自定义查询函数
	 * @return CActiveDataProvider 一个包含分页排序查询数据
	 */
	public function search()
	{
		$criteria=new CDbCriteria;

		$criteria->compare('name',$this->name,true);
		$criteria->compare('type',$this->type);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('bizrule',$this->bizrule,true);
		$criteria->compare('data',$this->data,true);
		$criteria->compare('modelid',$this->modelid);
		$criteria->compare('opertype',$this->opertype,true);
		$criteria->order='name desc';//排序字段

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
			'pagination'=>array(
                'pageSize'=>Yii::app()->params['pagesize'],//配置文件中设置过分页条数
            ),
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Authitem the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
